import prisma from "@/libs/prisma";
import { NextResponse } from "next/server";
import { getFoodTruck } from "@/app/actions";

export const PUT = async (req) => {
  const params = await req.json();
  console.log(params);
  const { id } = params;

  const foodTruck = await getFoodTruck(id);
  const data =
    (await prisma.foodTruck.update({
      where: { id },
      data: {
        isCollected: !foodTruck.isCollected,
        collectNum: !foodTruck.isCollected
          ? ++foodTruck.collectNum
          : --foodTruck.collectNum,
      },
    })) || {};

  return NextResponse.json({
    success: true,
    message: "",
    data,
  });
};
